<?php

namespace Luka\SecurityBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class LoginFormType extends AbstractType {
    private $translator;
    private $formData;

    public function __construct($translator){
        $this->translator = $translator;
    }

    public function buildForm(FormBuilder $builder, array $options) {
        $builder->add('username', 'text', array('label'  => $this->translator->trans('Kasutajanimi')));
        $builder->add('password', 'password', array('label'  => $this->translator->trans('Parool')));
    }

    public function bindFormData($formData){
        $this->formData = $formData;
    }

    public function getUsername(){
        return $this->getFormField("username");
    }

    public function getPassword(){
        return $this->getFormField("password");
    }

    private function getFormField($key){
        if(is_array($this->formData)){
            if(array_key_exists($key, $this->formData)){
                return $this->formData[$key];
            }
        }
        return "";
    }
    
    public function getName() {
        return 'login_form_type';
    }
}
